VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "DAOPedido"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
'---------------------------------------------------------------------------------------
' Module    : DAOPedido
' DateTime  : 30/11/2011 12:13
' Author    :
' Purpose   : Clase DAO Pedido
'---------------------------------------------------------------------------------------
Option Explicit
Private mvarConnection As utilConexion
Public Property Set Connection(ByVal vData As utilConexion)
    Set mvarConnection = vData
End Property

Public Function enviar(bean As bdetalle) As Integer
On Error GoTo hnderr
Dim sql As String
sql = "SELECT * FROM proc_ventadetalle_envia(" + CStr(bean.ncodigo) + ")"
mvarConnection.Connection.Execute sql
enviar = UtilConstantes.OPT_DATOS_GUARDADOS
hnderr:
If Err.Number = 0 Then Exit Function
enviar = UtilConstantes.OPT_ERROR_ENCONTRADO
Err.Clear

End Function


Public Function eliminar(bean As bpedido) As Integer
On Error GoTo hnderr
Dim sql As String
sql = "SELECT * FROM proc_venta_elimina(" + CStr(bean.ncodigo) + ")"
mvarConnection.Connection.Execute sql
eliminar = UtilConstantes.OPT_DATOS_ELIMINADOS
hnderr:
If Err.Number = 0 Then Exit Function
eliminar = UtilConstantes.OPT_ERROR_ENCONTRADO
Err.Clear
End Function
Public Function getPagos(ByRef bean As bpedido) As Integer
Dim sql As String
Dim rst As New Recordset
Dim list As New Collection
Dim record As New bPago
sql = "SELECT ncodigo, nformapago, sabreviatura, sformapago, resttotal, nesdolar, nmonto "
sql = sql + " FROM proc_pago_lista(" + CStr(bean.ncodigo) + ")"
rst.Open sql, mvarConnection.Connection, adOpenForwardOnly
While Not rst.EOF
    Set record = New bPago
    If Not IsNull(rst.Fields("ncodigo")) Then record.ncodigo = rst.Fields("ncodigo").value
    If Not IsNull(rst.Fields("nformapago")) Then record.BFormaPago.ncodigo = rst.Fields("nformapago").value
    If Not IsNull(rst.Fields("sabreviatura")) Then record.BFormaPago.sAbreviatura = rst.Fields("sabreviatura").value
    If Not IsNull(rst.Fields("sformapago")) Then record.BFormaPago.sdescripcion = rst.Fields("sformapago").value
    If Not IsNull(rst.Fields("resttotal")) Then record.BFormaPago.bRestTotal = rst.Fields("resttotal").value
    If Not IsNull(rst.Fields("nesdolar")) Then record.BFormaPago.bEsDolar = rst.Fields("nesdolar").value
    If Not IsNull(rst.Fields("nmonto")) Then record.nMonto = rst.Fields("nmonto").value
    rst.MoveNext
    list.Add record
Wend
Set bean.lPagos = list
If Err.Number = 0 Then Exit Function
getPagos = UtilConstantes.OPT_ERROR_ENCONTRADO
cloneError Err
End Function
Public Function getListaDetalle(ByRef bean As bpedido) As Integer
Dim sql As String
Dim rst As New Recordset
Dim list As New Collection
Dim record As New bdetalle
sql = "SELECT nindice , nproducto , sprodcodbarra,  sproducto , ncantidad , nmonto, nempleado , sempleado ,scodbarra, "
sql = sql + " ncomision ,    nprecunitario, snumcomanda, nimpreso, sobservacion "
sql = sql + " FROM proc_ventadetalle_lista("
sql = sql + CStr(bean.ncodigo) + ")"
rst.Open sql, mvarConnection.Connection, adOpenForwardOnly
bean.nTotal = 0
bean.nTotalSinDscto = 0
While Not rst.EOF
    Set record = New bdetalle
    If Not IsNull(rst.Fields("nindice")) Then record.ncodigo = rst.Fields("nindice").value
    If Not IsNull(rst.Fields("nproducto")) Then record.bproducto.ncodigo = rst.Fields("nproducto").value
    If Not IsNull(rst.Fields("sprodcodbarra")) Then record.bproducto.sCodBarra = rst.Fields("sprodcodbarra").value
    If Not IsNull(rst.Fields("sproducto")) Then record.bproducto.sdescripcionCorta = rst.Fields("sproducto").value
    If Not IsNull(rst.Fields("ncantidad")) Then record.nCantidad = rst.Fields("ncantidad").value
    If Not IsNull(rst.Fields("nmonto")) Then record.nMonto = rst.Fields("nmonto").value
    If Not IsNull(rst.Fields("nempleado")) Then record.bempleado.ncodigo = rst.Fields("nempleado").value
    If Not IsNull(rst.Fields("sempleado")) Then record.bempleado.sNombreCorto = rst.Fields("sempleado").value
    If Not IsNull(rst.Fields("scodbarra")) Then record.bempleado.sCodBarra = rst.Fields("scodbarra").value
    If Not IsNull(rst.Fields("ncomision")) Then record.nComision = rst.Fields("ncomision").value
    If Not IsNull(rst.Fields("nprecunitario")) Then record.nPrecio = rst.Fields("nprecunitario").value
    If Not IsNull(rst.Fields("snumcomanda")) Then record.sNumComanda = rst.Fields("snumcomanda").value
    If Not IsNull(rst.Fields("nimpreso")) Then record.nImpreso = rst.Fields("nimpreso").value
    If Not IsNull(rst.Fields("sobservacion")) Then record.sObservacion = rst.Fields("sobservacion").value
    record.nEstado = UtilConstantes.ESTADO_DETALLE_GUARDADO
    rst.MoveNext
    list.Add record
    bean.nTotalSinDscto = bean.nTotalSinDscto + record.nMonto
    bean.nTotal = bean.nTotalSinDscto - bean.nDescuento
Wend
Set bean.lDetalle = list
End Function
Public Function getListaDetalleImpresion(bean As bpedido) As Collection
Dim sql As String
Dim rst As New Recordset
Dim list As New Collection
Dim record As New bdetalle
sql = "SELECT scodbarra , sproducto , ncantidad , nprecunitario , nmonto  FROM  proc_ventadetalle_impresion_lista("
sql = sql + CStr(bean.ncodigo) + ")"
rst.Open sql, mvarConnection.Connection, adOpenForwardOnly
While Not rst.EOF
    Set record = New bdetalle
    If Not IsNull(rst.Fields("scodbarra")) Then record.bproducto.sCodBarra = rst.Fields("scodbarra").value
    If Not IsNull(rst.Fields("sproducto")) Then record.bproducto.sdescripcionCorta = rst.Fields("sproducto").value
    If Not IsNull(rst.Fields("ncantidad")) Then record.nCantidad = rst.Fields("ncantidad").value
    If Not IsNull(rst.Fields("nmonto")) Then record.nMonto = rst.Fields("nmonto").value
    If Not IsNull(rst.Fields("nprecunitario")) Then record.nPrecio = rst.Fields("nprecunitario").value
    record.nEstado = UtilConstantes.ESTADO_DETALLE_GUARDADO
    rst.MoveNext
    list.Add record
Wend
Set getListaDetalleImpresion = list
End Function
Public Function guardarNuevo(ByRef bean As bpedido) As Integer
On Error GoTo hnderr
Dim sql As String
Dim tb As New Recordset
sql = "select * from proc_venta_inserta('" + bean.bCompania.sRuc + "','" + bean.bCompania.bPuntoVenta.sSerie + "','"
sql = sql + bean.busuario.sNombre + "'," + CStr(bean.bEstado.ncodigo) + ","
sql = sql + CStr(bean.nTotal) + "," + CStr(bean.nBasImponible) + ","
sql = sql + CStr(bean.nIgv) + "," + CStr(bean.nServicio) + ",'" + CStr(bean.bMesa.sdescripcion) + "',"
sql = sql + CStr(bean.nDescuento) + "," + CStr(bean.nTipCambio) + ")"
Set tb = mvarConnection.Connection.Execute(sql)
bean.ncodigo = tb.Fields(0).value
bean.dFecha = tb.Fields(1).value
guardarNuevo = UtilConstantes.OPT_DATOS_GUARDADOS
hnderr:
If Err.Number = 0 Then Exit Function
guardarNuevo = UtilConstantes.OPT_ERROR_ENCONTRADO
cloneError Err
'Err.Clear
End Function
Public Function actualizar(bean As bpedido) As Integer
On Error GoTo hnderr
Dim sql As String
Dim sRuc As String
If Not bean.bCliente Is Nothing Then
    sRuc = bean.bCliente.sRuc
Else
    sRuc = ""
End If
sql = "select * from proc_venta_actualiza(" + CStr(bean.ncodigo) + ",'" + bean.bCompania.sRuc + "','"
sql = sql + bean.busuario.sNombre + "',"
sql = sql + CStr(bean.nTotalSinDscto) + "," + CStr(bean.nBasImponible) + ","
sql = sql + CStr(bean.nIgv) + "," + CStr(bean.nServicio) + ",'" + CStr(bean.bMesa.sdescripcion) + "',"
sql = sql + CStr(bean.nDescuento) + "," + CStr(bean.nTipCambio) + ", cast('" + sRuc + "' as character(11)))"

mvarConnection.Connection.Execute sql
actualizar = UtilConstantes.OPT_DATOS_GUARDADOS
hnderr:
If Err.Number = 0 Then Exit Function
actualizar = UtilConstantes.OPT_ERROR_ENCONTRADO
cloneError Err
Err.Clear
End Function
Public Function getPedidoPorMesa(bean As bMesa) As bpedido
Dim sql As String
Dim rst As New Recordset
Dim record As New bpedido
Dim i As Integer
sql = "SELECT scompania , srazonsocial , ncodigo , susuario ,  sserdocumento ,    snumdocumento , sruccliente, srazsoccliente,  "
sql = sql + " ncodtipcomprobante, sdestipcomprobante, nestado , sdesestado , ntotal , nbasimponible ,"
sql = sql + " nigv  , ndescuento , nservicio , sobservacion  , ntipcambio , dfecha ,nimpreso,ntotsindscto "
sql = sql + " FROM proc_mesa_lista('" + CStr(bean.ncodigo) + "') "
rst.Open sql, mvarConnection.Connection, adOpenForwardOnly
Set record.bMesa = bean
If Not rst.EOF Then
    If Not IsNull(rst.Fields("scompania")) Then record.bCompania.sRuc = rst.Fields("scompania").value
    Dim bCompania As bCompania
    For i = 1 To bparametro.lCompania.Count
        Set bCompania = bparametro.lCompania.Item(i)
        If bCompania.sRuc = record.bCompania.sRuc Then
            Set record.bCompania = bCompania
            Exit For
        End If
    Next
    If Not IsNull(rst.Fields("ncodigo")) Then record.ncodigo = rst.Fields("ncodigo").value
    If Not IsNull(rst.Fields("susuario")) Then record.busuario.sNombre = rst.Fields("susuario").value
    If Not IsNull(rst.Fields("sserdocumento")) Then record.sSerDocumento = rst.Fields("sserdocumento").value
    If Not IsNull(rst.Fields("snumdocumento")) Then record.sNumDocumento = rst.Fields("snumdocumento").value
    If Not IsNull(rst.Fields("sruccliente")) Then record.bCliente.sRuc = rst.Fields("sruccliente").value
    If Not IsNull(rst.Fields("srazsoccliente")) Then record.bCliente.sRazonSocial = rst.Fields("srazsoccliente").value
    If Not IsNull(rst.Fields("ncodtipcomprobante")) Then record.bTipoDocumento.ncodigo = rst.Fields("ncodtipcomprobante").value
    If Not IsNull(rst.Fields("sdestipcomprobante")) Then record.bTipoDocumento.sdescripcion = rst.Fields("sdestipcomprobante").value
    If Not IsNull(rst.Fields("nestado")) Then record.bEstado.ncodigo = rst.Fields("nestado").value
    If Not IsNull(rst.Fields("sdesestado")) Then record.bEstado.sdescripcion = rst.Fields("sdesestado").value
    If Not IsNull(rst.Fields("ntotal")) Then record.nTotal = rst.Fields("ntotal").value
    If Not IsNull(rst.Fields("ntotsindscto")) Then record.nTotalSinDscto = rst.Fields("ntotsindscto").value
    If Not IsNull(rst.Fields("nbasimponible")) Then record.nBasImponible = rst.Fields("nbasimponible").value
    If Not IsNull(rst.Fields("nigv")) Then record.nIgv = rst.Fields("nigv").value
    If Not IsNull(rst.Fields("nservicio")) Then record.nServicio = rst.Fields("nservicio").value
    If Not IsNull(rst.Fields("ndescuento")) Then record.nDescuento = rst.Fields("ndescuento").value
    If Not IsNull(rst.Fields("sobservacion")) Then record.sObservacion = rst.Fields("sobservacion").value
    If Not IsNull(rst.Fields("ntipcambio")) Then record.nTipCambio = rst.Fields("ntipcambio").value
    If Not IsNull(rst.Fields("dfecha")) Then record.dFecha = rst.Fields("dfecha").value
    If Not IsNull(rst.Fields("nimpreso")) Then record.bImpreso = rst.Fields("nimpreso").value
End If
Set getPedidoPorMesa = record
End Function
Public Function getLista(bean As bpedido) As Collection
Dim sql As String
Dim rst As New Recordset
Dim list As New Collection
Dim record As New bpedido
sql = "SELECT scompania, sserdocumento, sruccliente , srazsoccliente , dfecha, ncodigo , sserdocumento , snumdocumento , ntipcomprobante ,"
sql = sql + " stipcomprobante, susuario , nestado , sestado ,  nbasimponible ,"
sql = sql + " nigv     , ntipcambio , ntotal "
sql = sql + " FROM proc_venta_lista('" + bean.sNumDocumento + "'," + CStr(bean.ncodigo) + ")"
rst.Open sql, mvarConnection.Connection, adOpenForwardOnly
While Not rst.EOF
    Set record = New bpedido
    Dim i As Integer
    If Not IsNull(rst.Fields("scompania")) Then record.bCompania.sRuc = rst.Fields("scompania").value
    Dim bCompania As bCompania
    For i = 1 To bparametro.lCompania.Count
        Set bCompania = bparametro.lCompania.Item(i)
        If bCompania.sRuc = record.bCompania.sRuc Then
            Set record.bCompania = bCompania
            Exit For
        End If
    Next
    If Not IsNull(rst.Fields("ncodigo")) Then record.ncodigo = rst.Fields("ncodigo").value
    If Not IsNull(rst.Fields("sserdocumento")) Then record.sSerDocumento = rst.Fields("sserdocumento").value
    If Not IsNull(rst.Fields("snumdocumento")) Then record.sNumDocumento = rst.Fields("snumdocumento").value
    If Not IsNull(rst.Fields("ntipcomprobante")) Then record.bTipoDocumento.ncodigo = rst.Fields("ntipcomprobante").value
    If Not IsNull(rst.Fields("stipcomprobante")) Then record.bTipoDocumento.sdescripcion = rst.Fields("stipcomprobante").value
    If Not IsNull(rst.Fields("susuario")) Then record.busuario.sNombre = rst.Fields("susuario").value
    If Not IsNull(rst.Fields("nestado")) Then record.bEstado.ncodigo = rst.Fields("nestado").value
    If Not IsNull(rst.Fields("sestado")) Then record.bEstado.sdescripcion = rst.Fields("sestado").value
    If Not IsNull(rst.Fields("ntotal")) Then record.nTotal = rst.Fields("ntotal").value
    If Not IsNull(rst.Fields("nbasimponible")) Then record.nBasImponible = rst.Fields("nbasimponible").value
    If Not IsNull(rst.Fields("nigv")) Then record.nIgv = rst.Fields("nigv").value
    If Not IsNull(rst.Fields("ntipcambio")) Then record.nTipCambio = rst.Fields("ntipcambio").value
    If Not IsNull(rst.Fields("dfecha")) Then record.dFecha = rst.Fields("dfecha").value
    If Not IsNull(rst.Fields("sruccliente")) Then record.bCliente.sRuc = rst.Fields("sruccliente").value
    If Not IsNull(rst.Fields("srazsoccliente")) Then record.bCliente.sRazonSocial = rst.Fields("srazsoccliente")
    rst.MoveNext
    list.Add record
Wend
Set getLista = list
End Function
Public Function getListaPorRango(bean As BParmImpresionTickets) As Collection
Dim sql As String
Dim rst As New Recordset
Dim list As New Collection
Dim record As New bpedido
sql = "SELECT sruc , srazonsocial , ncodigo , sserdocumento , snumdocumento , ncodtipcomprobante ,"
sql = sql + "sdestipcomprobante , susuario , nestado , sdesestado , ntotal , nbasimponible ,"
sql = sql + " nigv , svoucher , ndescuento , sobservacion , scliente , ntipcambio , dfecha  "
sql = sql + " FROM proc_tickets_select_por_rango('" + Format(bean.nTicketIni, "0000000") + "' , '"
sql = sql + Format(bean.nTicketFin, "0000000") + "','" + bean.bCompania.sRuc + "' )"
rst.Open sql, mvarConnection.Connection, adOpenForwardOnly
While Not rst.EOF
    Set record = New bpedido
    Dim i As Integer
    If Not IsNull(rst.Fields("sruc")) Then record.bCompania.sRuc = rst.Fields("sruc").value
    Dim bCompania As bCompania
    For i = 1 To bparametro.lCompania.Count
        Set bCompania = bparametro.lCompania.Item(i)
        If bCompania.sRuc = record.bCompania.sRuc Then
            Set record.bCompania = bCompania
            Exit For
        End If
    Next
    If Not IsNull(rst.Fields("ncodigo")) Then record.ncodigo = rst.Fields("ncodigo").value
    If Not IsNull(rst.Fields("sserdocumento")) Then record.sSerDocumento = rst.Fields("sserdocumento").value
    If Not IsNull(rst.Fields("snumdocumento")) Then record.sNumDocumento = rst.Fields("snumdocumento").value
    If Not IsNull(rst.Fields("ncodtipcomprobante")) Then record.bTipoDocumento.ncodigo = rst.Fields("ncodtipcomprobante").value
    If Not IsNull(rst.Fields("sdestipcomprobante")) Then record.bTipoDocumento.sdescripcion = rst.Fields("sdestipcomprobante").value
    If Not IsNull(rst.Fields("susuario")) Then record.busuario.sNombre = rst.Fields("susuario").value
    If Not IsNull(rst.Fields("nestado")) Then record.bEstado.ncodigo = rst.Fields("nestado").value
    If Not IsNull(rst.Fields("sdesestado")) Then record.bEstado.sdescripcion = rst.Fields("sdesestado").value
    If Not IsNull(rst.Fields("ntotal")) Then record.nTotal = rst.Fields("ntotal").value
    If Not IsNull(rst.Fields("nbasimponible")) Then record.nBasImponible = rst.Fields("nbasimponible").value
    If Not IsNull(rst.Fields("nigv")) Then record.nIgv = rst.Fields("nigv").value
    If Not IsNull(rst.Fields("ndescuento")) Then record.nDescuento = rst.Fields("ndescuento").value
    If Not IsNull(rst.Fields("sobservacion")) Then record.sObservacion = rst.Fields("sobservacion").value
    If Not IsNull(rst.Fields("ntipcambio")) Then record.nTipCambio = rst.Fields("ntipcambio").value
    If Not IsNull(rst.Fields("dfecha")) Then record.dFecha = rst.Fields("dfecha").value
    rst.MoveNext
    list.Add record
Wend
Set getListaPorRango = list
End Function
Public Function guardaDetalle(bpedido As bpedido) As Integer
On Error GoTo hnderr
Dim sql As String
Dim tb As New Recordset
Dim i As Integer
Dim bean As bdetalle
bpedido.nTotal = 0
bpedido.nTotalSinDscto = 0
For i = 1 To bpedido.lDetalle.Count
    Set bean = bpedido.lDetalle.Item(i)
    If bean.nEstado = UtilConstantes.ESTADO_DETALLE_NUEVO Then
        sql = "select * from proc_ventadetalle_inserta(" + CStr(bean.nCantidad) + ","
        sql = sql + CStr(bean.bproducto.ncodigo) + "," + CStr(bean.nMonto) + ","
        sql = sql + CStr(bpedido.ncodigo) + "," + CStr(bean.bempleado.ncodigo) + ","
        sql = sql + CStr(bean.nPrecio) + ",'" + bean.sNumComanda + "','" + Trim(bean.sObservacion) + "'," & CStr(PRODUCTO_NO_IMPRESO) + ") "
        Set tb = mvarConnection.Connection.Execute(sql)
        bean.ncodigo = tb.Fields(0).value
        bean.nEstado = UtilConstantes.ESTADO_DETALLE_GUARDADO
    End If
    bpedido.nTotalSinDscto = bpedido.nTotalSinDscto + bean.nMonto
    bpedido.nTotal = bpedido.nTotalSinDscto - bpedido.nDescuento
Next
    guardaDetalle = UtilConstantes.OPT_DATOS_GUARDADOS
hnderr:
    If Err.Number = 0 Then Exit Function
    guardaDetalle = UtilConstantes.OPT_ERROR_ENCONTRADO
End Function
Public Function eliminarDetalle(bean As bdetalle) As Integer
'On Error GoTo hnderr
Dim sql As String
    If bean.nEstado = UtilConstantes.ESTADO_DETALLE_GUARDADO Then
        sql = "SELECT * FROM proc_ventadetalle_elimina(" + CStr(bean.ncodigo) + ")"
        mvarConnection.Connection.Execute sql
    End If
    eliminarDetalle = UtilConstantes.OPT_DATOS_ELIMINADOS
hnderr:
    If Err.Number = 0 Then Exit Function
    eliminarDetalle = UtilConstantes.OPT_ERROR_ENCONTRADO
    'Err.Clear
End Function
Public Function guardaPagos(bpedido As bpedido) As Integer
'On Error GoTo hnderr
Dim sql As String
Dim tb As New Recordset
Dim i As Integer
Dim bean As bPago
For i = 1 To bpedido.lPagos.Count
    Set bean = bpedido.lPagos.Item(i)
    If bpedido.nTotPagado > bpedido.nTotal Then
        If i = bpedido.lPagos.Count Then
            If bean.BFormaPago.bEsDolar Then
            bean.nMonto = (bean.nMonto * bpedido.nTipCambio) - (bpedido.nTotPagado - bpedido.nTotal)
            Else
            bean.nMonto = bean.nMonto - (bpedido.nTotPagado - bpedido.nTotal)
            End If
        End If
    End If
    sql = "select * from proc_ventapago_inserta(" + CStr(bean.BFormaPago.ncodigo)
    sql = sql + "," + Format(bean.nMonto, "##########.00")
    sql = sql + "," + CStr(bpedido.ncodigo) + ")"
    Set tb = mvarConnection.Connection.Execute(sql)
    bean.ncodigo = tb.Fields(0).value
Next
    bpedido.bEstado.ncodigo = UtilConstantes.ESTADO_PEDIDO_CANCELADO
    guardaPagos = UtilConstantes.OPT_DATOS_GUARDADOS
hnderr:
    If Err.Number = 0 Then Exit Function
    guardaPagos = UtilConstantes.OPT_ERROR_ENCONTRADO
End Function
Public Function cancelar(bean As bpedido) As Integer
On Error GoTo hnderr
Dim sql As String
    sql = "SELECT * FROM proc_venta_actualiza_estado (" + CStr(bean.ncodigo) + ", " + CStr(UtilConstantes.ESTADO_PEDIDO_CANCELADO) + " )"
    mvarConnection.Connection.Execute sql
    cancelar = UtilConstantes.OPT_DATOS_GUARDADOS
hnderr:
    If Err.Number = 0 Then Exit Function
    cancelar = UtilConstantes.OPT_ERROR_ENCONTRADO
    'Err.Clear
End Function
Public Function anular(bean As bpedido) As Integer
On Error GoTo hnderr
Dim sql As String
    sql = "SELECT * FROM proc_venta_actualiza_estado (" + CStr(bean.ncodigo) + ", " + CStr(UtilConstantes.ESTADO_PEDIDO_ANULADO) + " )"
    mvarConnection.Connection.Execute sql
    anular = UtilConstantes.OPT_DATOS_GUARDADOS
hnderr:
    If Err.Number = 0 Then Exit Function
    anular = UtilConstantes.OPT_ERROR_ENCONTRADO
    'Err.Clear
End Function
Public Function asignarNumeracion(bpedido As bpedido) As Integer
On Error GoTo hnderr
Dim sql As String
Dim rst As Recordset
    sql = "SELECT * FROM proc_venta_actualiza_numeracion (" + CStr(bpedido.ncodigo) + ",'" + bpedido.bCompania.bPuntoVenta.sSerie + "','" + CStr(bparametro.bUsuarioActivo.sNombre) + "')"
    Set rst = mvarConnection.Connection.Execute(sql)
    bpedido.sNumDocumento = Trim(rst.Fields(0).value)
    bpedido.bTipoDocumento.ncodigo = rst.Fields(1).value
    bpedido.bImpreso = True
    asignarNumeracion = UtilConstantes.OPT_DATOS_GUARDADOS
hnderr:
    If Err.Number = 0 Then Exit Function
    asignarNumeracion = UtilConstantes.OPT_ERROR_ENCONTRADO
End Function
Public Function actualizatdocumento(bpedido As bpedido) As Integer
On Error GoTo hnderr
Dim sql As String
Dim rst As Recordset
    sql = "SELECT * FROM proc_venta_actualiza_tdocumento (" + CStr(bpedido.ncodigo) + ") "
    Set rst = mvarConnection.Connection.Execute(sql)
    actualizatdocumento = UtilConstantes.OPT_DATOS_GUARDADOS
hnderr:
    If Err.Number = 0 Then Exit Function
    actualizatdocumento = UtilConstantes.OPT_ERROR_ENCONTRADO
End Function


Public Function ActualizaEmpleadoDetalle(bean As bdetalle) As Integer
On Error GoTo hnderr
Dim sql As String
sql = "Update ventadetalle set nempleado=" + CStr(bean.bempleado.ncodigo) + " where npedido=" + CStr(bean.ncodigo)
mvarConnection.Connection.Execute sql
ActualizaEmpleadoDetalle = UtilConstantes.OPT_DATOS_GUARDADOS
hnderr:
If Err.Number = 0 Then Exit Function
ActualizaEmpleadoDetalle = UtilConstantes.OPT_ERROR_ENCONTRADO
cloneError Err
Err.Clear
End Function

